<template>
  <el-row>
    <el-col>
      <el-table
          ref="multipleTable"
          border
          stripe
          :data="ListInfo"
          tooltip-effect="dark"
          style="width: 90%">
        <el-table-column
            type="selection"
            width="55">
        </el-table-column>
        <el-table-column
            prop="caseId"
            label="会诊id"
            width="100">
        </el-table-column>
        <el-table-column
            prop="doctorName"
            label="医生姓名"
            width="100">
        </el-table-column>
        <el-table-column
            prop="patientName"
            label="患者姓名"
            width="100">
        </el-table-column>

        <el-table-column
            prop="createTime"
            label="创建日期"
            width="100">
          <template slot-scope="scope">
            {{timeChange(scope.row.createTime)}}
          </template>
        </el-table-column>

        <el-table-column
            label="更多信息"
            width="100">
          <el-button
              slot-scope="scope"
              @click="showMoreInfo(scope.row)">
            查看
          </el-button>
        </el-table-column>

        <el-table-column
            label="会诊室"
            width="100">
          <el-button
              slot-scope="scope"
              @click="intoRoom(scope.row)">
            进入
          </el-button>
        </el-table-column>

      </el-table>
    </el-col>

    <!--其他信息弹出框-->
    <el-dialog :visible.sync="showMoreInfoDig">

      <el-descriptions
          title="更多信息"
          :column="1"
          border
          direction="vertical">

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            症状
          </template>
          {{textChange(moreInfo.symptom)}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            主诉
          </template>
          {{textChange(moreInfo.presentComplaint)}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            现病史
          </template>
          {{textChange(moreInfo.historyPC)}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            既往病史
          </template>
          {{textChange(moreInfo.medicalHistory)}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            诊断
          </template>
          {{textChange(moreInfo.diagnosis)}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            检查
          </template>
          {{textChange(moreInfo.examine)}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-document"></i>
            医嘱
          </template>
          {{textChange(moreInfo.advice)}}
        </el-descriptions-item>

      </el-descriptions>
    </el-dialog>

  </el-row>
</template>

<script>


export default {
  name: "inquiry.vue",
  data() {
    return{
      //更多消息窗
      showMoreInfoDig: false,
      //数据
      ListInfo: [
        {
          caseId: 0,
          drId: 0,
          patientId: 0,
          patientName: '',
          doctorName: '',
          createTime: '',
          updateItem: '',

          symptom: '',
          diagnosis: '',
          examine: '',
          advice: '',
          medicalHistory: '',
          presentComplaint: '',
          historyPC: ''
        }
      ],

      //文本显示
      moreInfo:{
        symptom: '',
        diagnosis: '',
        examine: '',
        advice: '',
        medicalHistory: '',
        presentComplaint: '',
        historyPC: ''
      },
      //当前用户
      userNow:{
        userId: 0,
        isDoctor: false,
      },
      //如果用户为医生-> 医生信息
      doctorNow:{
        drId: 0,
      }


    }
  },
   created() {
    this.getUserInfo();
  },
  methods:{

    getUserInfo(){
      const self = this;
      this.$axios.get('api/user/accessUser')
          .then(res => {
            self.userNow = res.data.data;
            if(self.userNow.isDoctor)
              this.$axios.get('api/doctor/accessDoctorInfo')
                  .then(res => {
                    self.doctorNow = res.data.data;
                    self.getInfoList();
                  })

            else
              self.getInfoList();
          })
    },

    getInfoList(){
      const self = this;
      let type = self.userNow.isDoctor ? 'doctor' : 'patient';
      let json = {
        'userType': type,
        'doctorId': self.doctorNow.drId,
        'userId': self.userNow.userId
      };


      self.$axios.post('api/inquiry/getHistoryInquiry',json)
          .then(res => {
            self.ListInfo = res.data.data;
          })
    },

    //获取详细信息
    showMoreInfo(val){
      const self = this;
      self.moreInfo.symptom = val.symptom;
      self.moreInfo.diagnosis =  val.diagnosis;
      self.moreInfo.examine =  val.examine;
      self.moreInfo.advice = val.advice;
      self.moreInfo.medicalHistory =  val.medicalHistory;
      self.moreInfo.presentComplaint = val.presentComplaint;
      self.moreInfo.historyPC = val.historyPC;

      self.showMoreInfoDig = true;
    },
    timeChange(val){
      let str = val.toString();
      str = str.substring(0,19).replace('T',' ');

      return str;

    },
    textChange(val){
      if(val === null){
        return '暂无信息';
      }
      return val;
    },

    intoRoom(val){
      const self = this;
      let inquiryId = val.caseId;
      let talkRoomPath = self.userNow.isDoctor
          ? "/talkRoom/doctor"
          : "/talkRoom/patient";

      this.$router.push({
        path: talkRoomPath,
        query: {
          inquiryId: inquiryId,
          userId: self.userNow.userId,
        }
      })
    }

  }
}
</script>

<style scoped>

</style>